define([
  'jquery',
  'underscore',
  'backbone',
  'collections/formdatas',
  'text!views/templates/list.html',
  'views/dialogview',
  'bootstrap'
], function ($, _, backbone, formdatasCollection, listTemplate,dialogview) {


var searchView = Backbone.View.extend({
    /* el: '#listcontent',*/
    el:'#searchform',

    template: _.template(listTemplate),

    initialize: function () {
      $("#searchalert").hide();
      //console.log('searchview init');
      //_.bindAll(this);
    },

    events: {
      'click #searchbtn': 'searchform',
      'submit form' : 'submitForm'
    },

    render: function () {
        //console.log('searchView');
        $("#homepage").show();
        return this;
    },

    searchrender: function (querystring) {

      this.beforesearch();
      this.beginloading();
      var contacts = new formdatasCollection();
      contacts.fetch({
        data: querystring,
        success: $.proxy(function (collection, response) {
          //this.$el.html(this.template({formdatas: response}));
          $("#listcontent").html(this.template({formdatas: response}));

          this.endloading();
        }, this),
        error: function (model, resp){
            this.endloading();
       }
      });

      return this;
    },
    beforesearch:function(){
      $("#homepage").hide();
    },
    beginloading:function(){
      $('.loading-bar').show();
    },

    endloading:function(){
      $('.loading-bar').hide();
    },

    submitForm:function(){

        console.log('submit form');
        event.preventDefault();
    },

    searchform: function () {

      //console.log(listTemplate);

      console.log(dialogview);

      dialogSigView = dialogview();

      console.log(dialogSigView);
      console.log(dialogSigView.hasajax);

      dialogSigView.getdialog();

      dialogSigView.opendialog();

      var full_name = $('#search-text').val();

      if(!full_name){
         $("#searchalert").show();
         return false;
      }

      //var listview = new listView();
      this.searchrender({action:"search",search: full_name});
      return false;
    },



  });


  return  {
        "searchView": searchView
  }

  //return listView;
});